Problem: Let $w_1$ and $w_2$ denote the circles $x^2+y^2+10x-24y-87=0$ and $x^2 +y^2-10x-24y+153=0,$ respectively. Let $m$ be the smallest positive value of $a$ for which the line $y=ax$ contains the center of a circle that is externally tangent to $w_2$ and internally tangent to $w_1.$ Given that $m^2=\frac pq,$ where $p$ and $q$ are relatively prime integers, find $p+q.$

Explanation: Rewrite the given equations as $(x+5)^2 + (y-12)^2 = 256$ and $(x-5)^2 + (y-12)^2 = 16$.
Let $w_3$ have center $(x,y)$ and radius $r$. Now, if two circles with radii $r_1$ and $r_2$ are externally tangent, then the distance between their centers is $r_1 + r_2$, and if they are internally tangent, it is $|r_1 - r_2|$. So we have
\begin{align*} r + 4 &= \sqrt{(x-5)^2 + (y-12)^2} \\ 16 - r &= \sqrt{(x+5)^2 + (y-12)^2} \end{align*}
Solving for $r$ in both equations and setting them equal, then simplifying, yields
\begin{align*} 20 - \sqrt{(x+5)^2 + (y-12)^2} &= \sqrt{(x-5)^2 + (y-12)^2} \\ 20+x &= 2\sqrt{(x+5)^2 + (y-12)^2} \end{align*}
Squaring again and canceling yields $1 = \frac{x^2}{100} + \frac{(y-12)^2}{75}.$
So the locus of points that can be the center of the circle with the desired properties is an ellipse.
[asy] size(220); pointpen = black; pen d = linewidth(0.7); pathpen = d;  pair A = (-5, 12), B = (5, 12), C = (0, 0); D(CR(A,16));D(CR(B,4));D(shift((0,12)) * yscale(3^.5 / 2) * CR(C,10), linetype("2 2") + d + red); D((0,30)--(0,-10),Arrows(4));D((15,0)--(-25,0),Arrows(4));D((0,0)--MP("y=ax",(14,14 * (69/100)^.5),E),EndArrow(4));  void bluecirc (real x) {  pair P = (x, (3 * (25 - x^2 / 4))^.5 + 12); dot(P, blue);  D(CR(P, ((P.x - 5)^2 + (P.y - 12)^2)^.5 - 4) , blue + d + linetype("4 4")); }  bluecirc(-9.2); bluecirc(-4); bluecirc(3); [/asy]
Since the center lies on the line $y = ax$, we substitute for $y$ and expand:\[1 = \frac{x^2}{100} + \frac{(ax-12)^2}{75} \Longrightarrow (3+4a^2)x^2 - 96ax + 276 = 0.\]
We want the value of $a$ that makes the line $y=ax$ tangent to the ellipse, which will mean that for that choice of $a$ there is only one solution to the most recent equation. But a quadratic has one solution iff its discriminant is $0$, so $(-96a)^2 - 4(3+4a^2)(276) = 0$.
Solving yields $a^2 = \frac{69}{100}$, so the answer is $\boxed{169}$.